
public class World {
	Engine eng;
	AnimObj player1;
	AnimObj player2;
	Ball	ball;
	Ground	back_ground;
	Ground	fore_ground;
	double	day_time;
	
	static float velo_x = 2.5f;
	 
	World(){
		eng = new Engine(800, 600);
		player1 = new AnimObj("left_player", 4, 4, 5);
		player2 = new AnimObj("right_player", 4, 4, 5);
		ball = new Ball("ball", 0, 0, 0);
		back_ground = new Ground("sky.png", 0, 0);
		fore_ground = new Ground("green.png", 0, 400);
		
		init();
	}
	public void init(){
		player1.x = 50;
		player1.y = 390;
		
		player2.x = 700;
		player2.y = 390;
		
		ball.x = 100;
		ball.y = 435;
		ball.setSpeeds(570, 500);
		
		back_ground.x = 0;
		back_ground.y = 0;
		
		fore_ground.x = 0;
		fore_ground.y = 420;
		
		day_time = 0;		
	}
	
	public void play(long dt) {
		
		//====Input==================
		if (eng.isPressed("1NUM")) {
			player1.playAnimation(2);
		}
		if (eng.isPressed("2NUM")) {
			player1.playAnimation(3);
		}
		if (eng.isPressed("A")) {
			player1.setAnimation(1);
			player1.x -= velo_x;
		}
		else if (eng.isPressed("D")) {
			player1.setAnimation(1);
			player1.x += velo_x;
		}
		else
			player1.setAnimation(0);
		
		if (eng.isPressed("LEFT")) {
			player2.setAnimation(1);
			player2.x -= velo_x;
		}
		else if (eng.isPressed("RIGHT")) {
			player2.setAnimation(1);
			player2.x += velo_x;
		}
		else
			player2.setAnimation(0);
		//============================
		
		ball.play(dt);
		
		player1.animate(dt);
		player2.animate(dt);
		ball.animate(dt);
	}
	
	public void render() {
		eng.drawSprite(back_ground.file_name, 0, 0);
		eng.drawSprite(fore_ground.file_name, 0, 420);
		
		eng.drawSprite(player1.sprite.get(player1.cur_sprite), (int)player1.x, (int)player1.y);
		eng.drawSprite(player2.sprite.get(player2.cur_sprite), (int)player2.x, (int)player2.y);
		eng.drawSprite(ball.sprite.get(ball.cur_sprite), (int)ball.x, (int)ball.y);
		
		eng.render();
	}
}
